package com.ajie.lib_base.ft_time;


import android.app.AlarmManager;
import android.content.Context;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import androidx.annotation.NonNull;

import com.ajie.lib_base.R;

import static android.content.Context.ALARM_SERVICE;

/**
 * Created by hanguoshuan on 2019/1/25.
 */
public class TimeZoneUtils {
    private final String TAG = "TimeZoneUtils";
    private String[] mZoneNameArray = {"Asia/Shanghai","America/Chicago","Europe/Moscow","Asia/Taipei","Europe/London","Pacific/Majuro","Pacific/Midway","Pacific/Honolulu","America/Anchorage","America/Los_Angeles","America/Tijuana","America/Phoenix","America/Chihuahua","America/Denver","America/Costa_Rica","America/Mexico_City","America/Regina","America/Bogota","America/New_York","America/Caracas","America/Barbados","America/Manaus","America/Santiago","America/St_Johns","America/Sao_Paulo","America/Argentina/Buenos_Aires","America/Godthab","America/Montevideo","Atlantic/South_Georgia","Atlantic/Azores","Atlantic/Cape_Verde","Africa/Casablanca","Europe/Amsterdam","Europe/Belgrade","Europe/Brussels","Europe/Sarajevo","Africa/Windhoek","Africa/Brazzaville","Asia/Amman","Europe/Athens","Asia/Beirut","Africa/Cairo","Europe/Helsinki","Asia/Jerusalem","Europe/Minsk","Africa/Harare","Asia/Baghdad","Asia/Kuwait","Africa/Nairobi","Asia/Tehran","Asia/Baku","Asia/Tbilisi","Asia/Yerevan","Asia/Dubai","Asia/Kabul","Asia/Karachi","Asia/Oral","Asia/Yekaterinburg","Asia/Calcutta","Asia/Colombo","Asia/Katmandu","Asia/Almaty","Asia/Rangoon","Asia/Krasnoyarsk","Asia/Bangkok","Asia/Hong_Kong","Asia/Irkutsk","Asia/Kuala_Lumpur","Australia/Perth","Asia/Seoul","Asia/Tokyo","Asia/Yakutsk","Australia/Adelaide","Australia/Darwin","Australia/Brisbane","Australia/Hobart","Australia/Sydney","Asia/Vladivostok","Pacific/Guam","Asia/Magadan","Pacific/Auckland","Pacific/Fiji","Pacific/Tongatapu"};
    private String[] mZoneArray={"(UTC+8:00)中国标准时间(北京)","(UTC-6:00)美国中部时间(芝加哥)","(UTC+3:00)俄罗斯(莫斯科)","(UTC+8:00)台北时间(台北)","(UTC+0:00)格林尼治标准时间(伦敦)","(UTC+12:00)马朱罗","(UTC-12:00)中途岛","(UTC-10:00)檀香山","(UTC-8:00)安克雷奇","(UTC-7:00)美国太平洋时间(洛杉矶)","(UTC-7:00)美国太平洋时间(提华纳)","(UTC-6:00)美国山区时间(凤凰城)","(UTC-6:00)奇瓦瓦","(UTC-6:00)美国山区时间(丹佛)","(UTC-6:00)美国中部时间(哥斯达黎加)","(UTC-5:00)美国中部时间(墨西哥城)","(UTC-6:00)美国中部时间(里贾纳)","(UTC-5:00)哥伦比亚时间(波哥大)","(UTC-4:00)美国东部时间(纽约)","(UTC-4:00)委内瑞拉时间(加拉加斯)","(UTC-4:00)大西洋时间(巴巴多斯)","(UTC+4:00)亚马逊标准时间(马瑙斯)","(UTC-4:00)圣地亚哥","(UTC-3:00)纽芬兰时间(圣约翰)","(UTC-3:00)圣保罗","(UTC-3:00)布宜诺斯艾利斯","(UTC-3:00)戈特霍布","(UTC-3:00)乌拉圭时间(蒙得维的亚)","(UTC-2:00)南乔治亚","(UTC-1:00)亚述尔群岛","(UTC-1:00)佛得角","(UTC+0:00)卡萨布兰卡","(UTC+0:00)中欧标准时间(阿姆斯特丹)","(UTC+0:00)中欧标准时间(贝尔格莱德)","(UTC+0:00)中欧标准时间(布鲁塞尔)","(UTC+0:00)中欧标准时间(萨拉热窝)","(UTC+1:00)温得和克","(UTC+1:00)西部非洲标准时间(布拉扎维)","(UTC+2:00)东欧标准时间(安曼)","(UTC+2:00)东欧标准时间(雅典)","(UTC+2:00)东欧标准时间(贝鲁特)","(UTC+2:00)东欧标准时间(开罗)","(UTC+3:00)东欧标准时间(赫尔辛基)","(UTC+3:00)以色列时间(耶路撒冷)","(UTC+3:00)明斯克","(UTC+2:00)中部非洲标准时间(哈拉雷)","(UTC+3:00)巴格达","(UTC+3:00)科威特","(UTC+3:00)东部非洲标准时间(内罗毕)","(UTC+4:00)伊朗标准时间(德黑兰)","(UTC+4:00)巴库","(UTC+4:00)第比利斯","(UTC+4:00)埃里温","(UTC+4:00)迪拜","(UTC+4:30)阿富汗时间(喀布尔)","(UTC+5:00)卡拉奇","(UTC+5:00)乌拉尔","(UTC+5:00)叶卡捷林堡","(UTC+5:30)加尔各答","(UTC+5:30)科伦坡","(UTC+5:45)尼泊尔时间(加德满都)","(UTC+6:00)阿拉木图","(UTC+6:00)缅甸时间(仰光)","(UTC+6:00)克拉斯诺亚尔斯克","(UTC+7:00)曼谷","(UTC+8:00)香港时间(香港)","(UTC+8:00)伊尔库茨克时间(伊尔库茨克)","(UTC+8:00)吉隆坡","(UTC+8:00)佩思","(UTC+9:00)首尔","(UTC+9:00)日本时间(东京)","(UTC+9:00)雅库茨克时间(雅库茨克)","(UTC+9:30)阿德莱德","(UTC+9:30)达尔文","(UTC+10:00)布里斯班","(UTC+10:00)霍巴特","(UTC+10:00)悉尼","(UTC+10:00)海参崴时间(符拉迪沃斯托克)","(UTC+10:00)关岛","(UTC+10:00)马加丹时间(马加丹)","(UTC+12:00)奥克兰","(UTC+12:00)斐济","(UTC+12:00)东加塔布"};
    private static Context mContext;

    public TimeZoneUtils() {
        Log.i(TAG, "TimeZoneUtils: construct: ");
    }

    //new Date() 会被影响 eg:
    // Tue Sep 22 15:45:28 GMT+09:00 2020 1600757128766
    // Tue Sep 22 14:45:36 GMT+08:00 2020 1600757136768
    //System.currentTimeMillis()  没影响
    public void setTimeZone(String timeZoneStr) {
        Log.i(TAG, "setTimeZone: "+timeZoneStr);
        if (TextUtils.isEmpty(timeZoneStr))return;

        for (String str:mZoneNameArray) {
            if (timeZoneStr.equalsIgnoreCase(str)){
                AlarmManager alarmManager = (AlarmManager) mContext.getSystemService(ALARM_SERVICE);
                alarmManager.setTimeZone(str);
                Log.i(TAG, "setTimeZone: AlarmManager setTimeZone over "+str);
                break;
            }
        }
    }

    private static class SingletonHolder{
        private static final TimeZoneUtils INSTANCE = new TimeZoneUtils();
    }

    public static TimeZoneUtils getIntance(@NonNull Context context){
        mContext = context.getApplicationContext();
        return SingletonHolder.INSTANCE;
    }
}
